package com.zwz.service.impl;

import com.mysql.cj.util.StringUtils;
import com.zwz.crawler.mangeInfo.TungeeCourtCaseQuery;
import com.zwz.dto.CourtAnnouncementDTO;
import com.zwz.entity.CourtAnnouncement;
import com.zwz.entity.EnterpriseInfo;
import com.zwz.entity.RiskInfoMain;
import com.zwz.mapper.CourtAnnouncementMapper;
import com.zwz.mapper.RiskInfoMainMapper;
import com.zwz.service.CourtAnnouncementService;
import com.zwz.voObject.CourtCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class CourtAnnouncementServiceImpl implements CourtAnnouncementService {

    @Autowired
    private RiskInfoMainMapper mainMapper;

    @Autowired
    private CourtAnnouncementMapper announcementMapper;

    @Override
    public CourtAnnouncementDTO createWithMain( String enterpriseId, CourtAnnouncement announcement ) {
        // 创建主表记录
        // 主表操作
        EnterpriseInfo enterpriseInfo=new EnterpriseInfo();
        enterpriseInfo.setId(Long.valueOf(enterpriseId));

        // 设置子表关联
//        CourtAnnouncement announcement = new CourtAnnouncement();
//        announcement.setId(main.getId());
        //真实数据必填

        // todo 先业务校验
        validateAnnouncement(announcement);

        //最后关联上
        announcement.setEnterpriseId(Math.toIntExact(enterpriseInfo.getId()));
        // 插入子表
        announcementMapper.insert(announcement);

        return new CourtAnnouncementDTO(enterpriseInfo, announcement);
    }

    @Override
    public void updateAnnouncement(CourtAnnouncement announcement) {

    }

    @Override
    public CourtCase getCourseInfo(String id) {
        return announcementMapper.selectByEnterpriseId(id);
    }

    private RiskInfoMain createMainRecord(Integer companyId) {
        RiskInfoMain main = new RiskInfoMain();
        main.setCompanyId(companyId);
        mainMapper.insert(main);
        return main;
    }

    private void validateAnnouncement(CourtAnnouncement announcement) {

        //todo 框架嵌入全局校验
//        if (announcement.getHasCourtSession()) {
//            throw new IllegalArgumentException("开庭公告必须包含开庭日期");
//        }


    }
}